﻿using PowerBooking.RSE.Contract.DTO;
using PowerBooking.RSE.Domain.Models;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PowerBooking.RSE.Domain.Factories
{
    public class ModelToDTO
    {
        public static SpiderDTO Spider(Spider spider)
        {
            return new SpiderDTO()
            {
                SpiderID = spider.SpiderID,
                Name = spider.Name,
                Url = spider.Url,
                Cities = Cities(spider.Cities)
            };
        }

        public static List<CityDTO> Cities(List<City> cities)
        {
            var cityDTOs = new ConcurrentBag<CityDTO>();
            Parallel.ForEach(cities, (c) => { cityDTOs.Add(new CityDTO() { CityID = c.CityID, Name = c.Name, Url = c.Url, Filters = Filters(c.Filters), Restaurants = Restaurants(c.Restaurants) }); });
            return cityDTOs.ToList();
        }

        public static List<FilterDTO> Filters(List<Filter> filters)
        {
            var filterDTOs = new ConcurrentBag<FilterDTO>();
            Parallel.ForEach(filters, (f) => { filterDTOs.Add(new FilterDTO() { FilterID = f.FilterID, Name = f.Name, Url = f.Url }); });
            return filterDTOs.ToList();
        }

        public static List<RestaurantDTO> Restaurants(List<Restaurant> restaurants)
        {
            var restaurantDTOs = new ConcurrentBag<RestaurantDTO>();
            Parallel.ForEach(restaurants, (r) =>
            {
                restaurantDTOs.Add(new RestaurantDTO()
                {
                    Address = r.Address,
                    CuisineTags = r.CuisineTags,
                    Environment = r.Environment,
                    Name = r.Name,
                    PerCapita = r.PerCapita,
                    RecentOrders = r.RecentOrders,
                    RegionTags = r.RegionTags,
                    RestaurantID = r.RestaurantID,
                    Reviews = r.Reviews,
                    Service = r.Service,
                    Taste = r.Taste,
                    Url = r.Url
                });
            });
            return restaurantDTOs.ToList();
        }
    }
}
